<template>
  <div class="user-profile-page">
    <h2>个人中心</h2>
    <el-form :model="userInfo" label-width="80px" style="max-width: 400px;">
      <el-form-item label="用户名">
        <el-input v-model="userInfo.name" />
      </el-form-item>
      <el-form-item label="邮箱">
        <el-input v-model="userInfo.email" />
      </el-form-item>
      <el-form-item label="手机号">
        <el-input v-model="userInfo.phone" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="updateProfile">保存修改</el-button>
      </el-form-item>
    </el-form>
    <el-divider>已报名活动</el-divider>
    <el-table :data="registeredActivities" style="width: 100%">
      <el-table-column prop="title" label="活动名称" />
      <el-table-column prop="status" label="状态" />
      <el-table-column prop="registerTime" label="报名时间" />
    </el-table>
  </div>
</template>

<script setup>
import { ref, onMounted } from 'vue'
import { useUserStore } from '@/stores/user'
import { ElMessage } from 'element-plus'
import { getUserRegisteredActivities } from '@/api/user'

const userStore = useUserStore()
const userInfo = ref({
  name: userStore.name,
  email: userStore.email,
  phone: userStore.phone
})
const registeredActivities = ref([])

const updateProfile = async () => {
  // 调用后端API保存
  // await updateUserProfile(userInfo.value)
  ElMessage.success('保存成功')
}

onMounted(async () => {
  const res = await getUserRegisteredActivities(userStore.id)
  if (res.code === 200) {
    registeredActivities.value = res.data
  }
})
</script>

<style scoped>
.user-profile-page {
  padding: 40px 20px;
  max-width: 900px;
  margin: 0 auto;
}
</style> 